package com.maoye.ossp.biz.statement.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.maoye.ossp.biz.statement.entity.StatementSaleDetail;
import com.maoye.ossp.biz.statement.entity.StatementSaleNote;
import com.maoye.ossp.biz.statement.service.StatementSaleDetailService;
import com.maoye.ossp.common.excel.ExportExcel;

@Controller
@RequestMapping(value = "biz/statement/statementSaleDetail")
public class StatementSaleDetailController {
	@Resource
	private StatementSaleDetailService statementSaleDetailSerice;
	/**
	 * 查询销售单明细信息,列表展示
	 * @param statementSaleNote
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@RequestMapping(value = "list")
	public String list(StatementSaleDetail statementSaleDetail, HttpServletRequest request,
			HttpServletResponse response, Model model) {
		String billNo = request.getParameter("billNo");
		Map map = new HashMap();
		map.put("billNo", billNo);
		List<StatementSaleDetail> list = statementSaleDetailSerice.getByBillNo(map);
		model.addAttribute("billNo", billNo);
		model.addAttribute("saleDate", request.getParameter("saleDate"));
		model.addAttribute("supplierNo", request.getParameter("supplierNo"));
		model.addAttribute("billNo", billNo);
		model.addAttribute("list", list);
		return "/biz/statement/statementSaleDetail/list";
	}
	/**
	 * 查看销售明细单详细信息
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "view")
	public String view( HttpServletRequest request,
			HttpServletResponse response, Model model) {
		String id = request.getParameter("id");
		StatementSaleDetail statementSaleDetail = statementSaleDetailSerice.get(id);
		model.addAttribute("statementSaleDetail",statementSaleDetail);
		return "/biz/statement/statementSaleDetail/view";
	}
	/**
	 * 导出数据到Excel
	 * @param request
	 * @param model
	 * @param redirectAttributes
	 * @return
	 */
	@RequestMapping(value = "exportExcel")
	public String exportExcel (HttpServletRequest request,Model model,RedirectAttributes redirectAttributes){
		String billNo = request.getParameter("billNo");
		Map map = new HashMap();
		map.put("billNo", billNo);
		List<StatementSaleDetail> list = statementSaleDetailSerice.getByBillNo(map);
		ExportExcel.exportExcel(billNo+"销售明细表", list, StatementSaleDetail.class, request);
		return "/excel/exceportToExcel";
	}
	
	private void addMessage(RedirectAttributes redirectAttributes, String string) {
		// TODO Auto-generated method stub
		
	}

	public StatementSaleDetailService getStatementSaleDetailSerice() {
		return statementSaleDetailSerice;
	}

	public void setStatementSaleDetailSerice(
			StatementSaleDetailService statementSaleDetailSerice) {
		this.statementSaleDetailSerice = statementSaleDetailSerice;
	}
}
